<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\erp\logic;
use think\facade\Hook;
use think\DB;
use util\Tree;
use think\facade\Debug;
use think\facade\Cache;
class GoodsClassTemplogic{

	/**
     * 分类列表
     * @param  int $user_id  操作用户ID
     * @author shiqiang
     * @return mixed
     */
    public function index($user_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' => $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			
			$list = model('ErpGoodsClassTemp', 'model') -> getClass();//获取列表
			
            // foreach($list as $key => $value){
				// $rel_list[$key]['id'] 			= (int)$value['id'];
				// $rel_list[$key]['pid'] 			= (int)$value['pid'];
				// $rel_list[$key]['title'] 		= (string)$value['title'];
				// $rel_list[$key]['sort'] 		= (int)$value['sort'];
				// $rel_list[$key]['level']		= (string)$value['level'];
				// $rel_list[$key]['createTime'] 	= (int)$value['create_time'];
			// }
			
			
			//第一步 构造数据
			$items = array();
			foreach($list as $value){
				$items[$value['id']] = $value;
			}
			//第二部 遍历数据 生成树状结构
			$tree = array();
			foreach($items as $key => $value){
				$items[$key] = [];
				$items[$key]['id'] 			= (int)$value['id'];
				$items[$key]['pid'] 		= (int)$value['pid'];
				$items[$key]['title'] 		= (string)$value['title'];
				$items[$key]['sort'] 		= (int)$value['sort'];
				$items[$key]['level']		= (int)$value['level'];
				$items[$key]['createTime'] 	= (int)$value['create_time'];
				if($value['level'] < 3) $items[$key]['childs'] = [];
				
				if(isset($items[$value['pid']])){
					$items[$value['pid']]['childs'][] = &$items[$key];
				}else{
					$tree[] = &$items[$key];
				}
			}
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $tree);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 分类列表 - level3 只显示有3级类目的
     * @param  int $user_id  操作用户ID
     * @author shiqiang
     * @return mixed
     */
    public function index_level3($user_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' => $user_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			
			$list = model('ErpGoodsClassTemp', 'model') -> getClass();//获取列表
			//第一步 构造数据
			$items = array();
			foreach($list as $value){
				$items[$value['id']] = $value;
			}
			//第二部 遍历数据 生成树状结构
			$tree = array();
			foreach($items as $key => $value){
				$items[$key] = [];
				$items[$key]['id'] 			= (int)$value['id'];
				$items[$key]['pid'] 		= (int)$value['pid'];
				$items[$key]['title'] 		= (string)$value['title'];
				$items[$key]['sort'] 		= (int)$value['sort'];
				$items[$key]['level']		= (int)$value['level'];
				$items[$key]['createTime'] 	= (int)$value['create_time'];
				if($value['level'] < 3) $items[$key]['childs'] = [];
				
				if(isset($items[$value['pid']])){
					$items[$value['pid']]['childs'][] = &$items[$key];
				}else{
					$tree[] = &$items[$key];
				}
			}
			
			foreach($tree as $key => $value){
				if($value['level'] == 1 && empty($value['childs'])){
					unset($tree[$key]);
				}else{
					foreach($value['childs'] as $k => $childs){
						if($childs['level'] == 2 && empty($childs['childs'])){
							unset($tree[$key]['childs'][$k]);
						}
					}
					$tree[$key]['childs'] = array_values($tree[$key]['childs']);
				}
			}
			$tree = array_values($tree);
			
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $tree);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	
	/**
     * 添加
     * @param  int    $user_id   操作用户ID
     * @param  int    $pid  	 父级id（顶级 = 0）
     * @param  string $title  	 分类标题
     * @param  int    $sort  	 分类排序
     * @author shiqiang
     * @return mixed
     */
    public function add($user_id, $pid, $title, $sort){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 	=> $user_id,
				'pid' 		=> $pid,
				'title' 	=> $title,
				'sort' 		=> $sort,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$father_path = '';
			if($pid > 0){
				$father_path = model('ErpGoodsClassTemp') -> find($pid) -> path;//上级path
				$level = explode('-', $father_path);
				if(count($level) > 2){
					DB::rollback();
					return array_out(-1005, 'error3');//类目不能超过3级
				}
			}
			
			$rel = model('ErpGoodsClassTemp') -> addData($pid, $title, $sort);//添加
			if($rel['code'] == 200){
				$id 		= $rel['data'];
				$path 		= $id;
				if($father_path != ''){
					$path = $father_path . '-' .$path;//重组path
				}
				$rel = model('ErpGoodsClassTemp') -> updateDataByPath($id, $path);
				if($rel['code'] < 0){
					DB::rollback();
					return array_out(-1005, 'error2');//path更新失败 返回-1005,error
				}
			}else{
				DB::rollback();
                return array_out(-1005, 'error');//添加失败 返回-1005,error
			}

            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 编辑
     * @param  int    $user_id   操作用户ID
     * @param  int    $id  		 分类id
     * @param  int    $pid  	 父级id（顶级 = 0）
     * @author shiqiang
     * @return mixed
     */
    public function edit($user_id, $id, $pid, $title, $sort){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 	=> $user_id,
				'id' 		=> $id,
				'pid' 		=> $pid,
				'title' 	=> $title,
				'sort' 		=> $sort,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$father_path = '';
			$new_path = $id;
			if($pid > 0){
				$father_path = model('ErpGoodsClassTemp') -> find($pid) -> path;//上级path
				$level = explode('-', $father_path);
				if(count($level) > 2){
					DB::rollback();
					return array_out(-1005, 'error3');//类目不能超过3级
				}
				$new_path = $father_path . '-' .$new_path;//重组path
			}
			
			$rel = model('ErpGoodsClassTemp') -> editData($id ,$pid, $title, $sort);
			if($rel['code'] == 200){
				// $path = model('ErpGoodsClassTemp') -> find($id) -> path;
				// $childs_path = model('ErpGoodsClassTemp') -> getChildsPath($id);//所有子集path
				// $childs_path[$id] = $new_path; //本条数据 插入数据集
				// foreach($childs_path as $key => $value){
					// $path	= str_replace($path, $new_path, $value);
					// $rel = model('ErpGoodsClassTemp') -> updateDataByPath($key, $path);
					// if($rel['code'] < 0){
						// DB::rollback();
						// return array_out(-1005, 'error2');//path更新失败 返回-1005,error
					// }
				// }
			}else{
				DB::rollback();
                return array_out(-1005, 'error');//编辑失败 返回-1005,error
			}

            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 删除
     * @param  int    $user_id   操作用户ID
     * @param  int    $id  分类id
     * @author shiqiang
     * @return mixed
     */
    public function delete($user_id, $id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 	=> $user_id,
				'id' 		=> $id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			
			$class_childs = model('ErpGoodsClassTemp') -> getChildsId($id); // 获取所有子类id
			$all_id = array_merge([(int)$id], $class_childs);// 要删除的所有id
			$rel = model('ErpGoodsClassTemp') -> deleteData($all_id);
			if($rel['code'] < 0){
				return array_out(-1005, 'error');//删除失败 返回-1005,error
			}
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 规格列表
     * @param  int $user_id  操作用户ID
     * @param  int $id  	 类目id
     * @author shiqiang
     * @return mixed
     */
    public function specifications_list($user_id, $classtemp_id, $title = ''){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 		=> $user_id,
				'classtemp_id' 	=> $classtemp_id,
				'title' 		=> $title,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$map = [];
			if($title != '' )$map[] = ['title', 'like', '%'. $title .'%'];
			$list = model('ErpSpecifications') -> where($map) -> order('sort asc, create_time desc') -> paginate();//所有规格
			$relation_list = model('ErpGoodsClasstempSpecifications') -> where('classtemp_id', $classtemp_id) -> column('specifications_id');//已选择
			
			$rel_list = [];
            foreach($list as $key => $value){
				$sid = $value['id'];
				$rel_list[$key]['specificationsId'] = (int)$value['id'];
				$rel_list[$key]['title'] 			= (string)$value['title'];
				
				$attribute_list = model('ErpSpecificationsAttribute') -> where('sid', $sid) -> order('sort asc, create_time desc') -> column('title');//规格属性列表
				$rel_list[$key]['attributeTitle'] 	= (array)$attribute_list;
				
				if(!empty($relation_list) && in_array($sid, $relation_list)){//是否选中
					$rel_list[$key]['isSpecifications'] = 1;//已选择
				}else{
					$rel_list[$key]['isSpecifications'] = 0;
				}
			}
			
			$result_list = [];
            $result_list['total']  			= (int)$list -> total();//总数
            $result_list['current_page']	= (int)$list -> currentPage();//页码
            $result_list['last_page']   	= (int)$list -> lastPage();//总页数
            $result_list['per_page']   		= (int)$list -> listRows();//每页条数
            $result_list['data'] 			= $rel_list;
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $result_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 规格设置
     * @param  int    $user_id   操作用户ID
     * @param  int    $id  分类id
     * @param  array  $specifications_id  规格id
     * @author shiqiang
     * @return mixed
     */
    public function specifications_add($user_id, $classtemp_id, $specifications_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 			=> $user_id,
				'classtemp_id' 		=> $classtemp_id,
				'specifications_id' => $specifications_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/
	
            /********业务逻辑********/
			if(count($specifications_id) > 2){
				DB::rollback();
				return array_out(-1005, 'error3');//规格不成超过2项
			}
			
			$path = model('ErpGoodsClassTemp') -> find($classtemp_id) -> path;
			$level = explode('-', $path);
			if(count($level) != 3){
				DB::rollback();
				return array_out(-1005, 'error4');//只能给第3级设置规格
			}
			
			$old_sid = model('ErpGoodsClasstempSpecifications') -> where('classtemp_id', $classtemp_id) -> column('id');//查出原有关联 并删除
			if(!empty($old_sid)){
				$rel = model('ErpGoodsClasstempSpecifications') -> deleteData($old_sid);
				if($rel['code'] < 0){
					DB::rollback();
					return array_out(-1005, 'error2'); //删除失败
				}
			}
			foreach($specifications_id as $sid){
				$rel = model('ErpGoodsClasstempSpecifications') -> addData($classtemp_id, $sid);//插入新的关联规格id
				if($rel['code'] < 0){
					DB::rollback();
					return array_out(-1005, 'error1'); //插入失败
				}
			}
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 参数列表
     * @param  int $user_id  操作用户ID
     * @param  int $classtemp_id  	类目id
     * @author shiqiang
     * @return mixed
     */
    public function parameter_list($user_id, $classtemp_id, $title = ''){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 			=> $user_id,
				'classtemp_id' 		=> $classtemp_id,
				'title' 			=> $title,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$map = [];
			if($title != '' )$map[] = ['title', 'like', '%'. $title .'%'];
			$list = model('ErpParameter') -> where($map) -> order('sort asc, create_time desc') -> paginate();//所有参数
			$relation_list = model('ErpGoodsClasstempParameter') -> where('classtemp_id', $classtemp_id) -> column('parameter_id');//已选择
			
			$rel_list = [];
            foreach($list as $key => $value){
				$pid = $value['id'];
				$rel_list[$key]['parameterId'] = (int)$value['id'];
				$rel_list[$key]['title'] 	   = (string)$value['title'];
				
				$attribute_list = model('ErpParameterAttribute') -> where('pid', $pid) -> order('sort asc, create_time desc') -> column('title');//参数属性列表
				$rel_list[$key]['attributeTitle'] 	= (array)$attribute_list;
				
				if(!empty($relation_list) && in_array($pid, $relation_list)){//是否选中
					$rel_list[$key]['isParameter'] = 1;//已选择
				}else{
					$rel_list[$key]['isParameter'] = 0;
				}
			}
			
			$result_list = [];
            $result_list['total']  			= (int)$list -> total();//总数
            $result_list['current_page']	= (int)$list -> currentPage();//页码
            $result_list['last_page']   	= (int)$list -> lastPage();//总页数
            $result_list['per_page']   		= (int)$list -> listRows();//每页条数
            $result_list['data'] 			= $rel_list;
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $result_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
     * 参数设置
     * @param  int    $user_id   操作用户ID
     * @param  int    $id  分类id
     * @param  array  $parameter_id  参数id
     * @author shiqiang
     * @return mixed
     */
    public function parameter_add($user_id, $classtemp_id, $parameter_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 			=> $user_id,
				'classtemp_id' 		=> $classtemp_id,
				'parameter_id' 		=> $parameter_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			if(count($parameter_id) > 20){
				DB::rollback();
				return array_out(-1005, 'error3');//参数不成超过20项
			}
			
			$path = model('ErpGoodsClassTemp') -> find($classtemp_id) -> path;
			$level = explode('-', $path);
			if(count($level) != 3){
				DB::rollback();
				return array_out(-1005, 'error4');//只能给第3级设置参数
			}
			
			$old_sid = model('ErpGoodsClasstempParameter') -> where('classtemp_id', $classtemp_id) -> column('id');//查出原有关联 并删除
			if(!empty($old_sid)){
				$rel = model('ErpGoodsClasstempParameter') -> deleteData($old_sid);
				if($rel['code'] < 0){
					DB::rollback();
					return array_out(-1005, 'error2'); //删除失败
				}
			}
			foreach($parameter_id as $pid){
				$rel = model('ErpGoodsClasstempParameter') -> addData($classtemp_id, $pid);//插入新的关联规格id
				if($rel['code'] < 0){
					DB::rollback();
					return array_out(-1005, 'error1'); //插入失败
				}
			}
			
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success');
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
	
	/**
      * 参数规格列表 - 类目已选中的
     * @param  int    $user_id   操作用户ID
     * @param  int    $id  分类id
     * @author shiqiang
     * @return mixed
     */
    public function parameter_specifications($user_id, $classtemp_id){
        DB::startTrans();//启动事务
        try{
            /********行为参数赋值（*）********/
            $params = [
				'user_id' 			=> $user_id,
				'classtemp_id' 		=> $classtemp_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
			$parameter_list 		= model('ErpGoodsClasstempParameter') -> where('classtemp_id', $classtemp_id) -> column('parameter_id');//已选择
			$specifications_list 	= model('ErpGoodsClasstempSpecifications') -> where('classtemp_id', $classtemp_id) -> column('specifications_id');//已选择
			
			$parameter_arr 			= [];
			$specifications_arr 	= [];
			foreach($parameter_list as $parameter_id){
				$parameter_info = model('ErpParameter') -> find($parameter_id);//所有参数
				
				$attribute_list = model('ErpParameterAttribute') -> where('pid', $parameter_id) -> order('sort asc, create_time desc') -> column('id as attributeId,title,sort');//参数属性列表
				sort($attribute_list);
				$parameter_arr[] = [
					'parameterId' 		=> (int)$parameter_info['id'],
					'title' 			=> (string)$parameter_info['title'],
					'attribute'			=> (array)$attribute_list,
				];
			}
			
			foreach($specifications_list as $specifications_id){
				$specifications_info = model('ErpSpecifications') -> find($specifications_id);//所有参数
				
				$attribute_list = model('ErpSpecificationsAttribute') -> where('sid', $specifications_id) -> order('sort asc, create_time desc') -> column('id as attributeId,title,sort');//规格属性列表
				sort($attribute_list);
				$specifications_arr[] = [
					'specificationsId' 	=> (int)$specifications_info['id'],
					'title' 			=> (string)$specifications_info['title'],
					'attribute'			=> (array)$attribute_list,
				];
			}
			
			$rel_list = [];
			$rel_list['parameter_arr'] 		= $parameter_arr;
			$rel_list['specifications_arr'] = $specifications_arr;
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $rel_list);
            /********逻辑返回********/
			
        } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        }
    }
}